package com.wisezone.springmvc.controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class AdviceController {
	/**
	 * Exception ex参数必须定义
	 * @param model
	 * @param ex
	 * @return
	 */
	@ExceptionHandler(value= {ArithmeticException.class,ArrayIndexOutOfBoundsException.class})
	public String onError(Model model,Exception ex) {
		if(ex instanceof ArrayIndexOutOfBoundsException) {
			model.addAttribute("error_message","ArrayIndexOutOfBoundsException 数组越界"+ex.getMessage());
		}else if(ex instanceof ArithmeticException) {
			model.addAttribute("error_message","ArithmeticException 除数不能为零"+ex.getMessage());
		}
		return "error";
	}
	@ExceptionHandler
	public String onOtherError(Exception ex) {
		
		return "error";
	}
}
